﻿/*
副本：	飞龙道场
 */
var mobid;
var mob;
var stats;
var modified;
var MaxRandom;
var setupTask;
var ostats;
var victor;

var mapID = 706041710;
var DPS = 13000;
var EXP = 10000000;

var dropItems = new Array(
		new Array(9803006, 2430144, 39, 1, 1), //秘密能手册
		new Array(9803006, 2430144, 39, 1, 1), //秘密能手册
		new Array(9803006, 4310143, 100, 1, 1), //BOSS币
		new Array(9803006, 2614003, 30, 1, 1), //突破10W之石
		new Array(9803006, 5390031, 70, 1, 1), //情景喇叭
		new Array(9803006, 5062000, 70, 1, 1), //一般神奇魔方
		new Array(9803006, 5062002, 35, 1, 1), //高级神奇魔方
		new Array(9803006, 5062009, 20, 1, 1), //超级神奇魔方
		new Array(9803006, 5062010, 14, 1, 1), //终极神奇魔方
		new Array(9803006, 5062001, 14, 1, 1), //混沌神奇魔方
		new Array(9803006, 5062500, 20, 1, 1), //大师附加魔方
		new Array(9803006, 2049137, 22, 1, 1), //惊人正义混沌卷轴 40%
		new Array(9803006, 5150040, 8, 1, 1), //皇家理发卷
		new Array(9803006, 5152053, 8, 1, 1), //皇家整容圈
		//===========================
		new Array(9803007, 2430144, 39, 1, 1), //秘密能手册
		new Array(9803007, 2430144, 39, 1, 1), //秘密能手册
		new Array(9803007, 4310143, 100, 1, 1), //BOSS币
		new Array(9803007, 2614003, 30, 1, 1), //突破10W之石
		new Array(9803007, 5390031, 70, 1, 1), //情景喇叭
		new Array(9803007, 5062000, 70, 1, 1), //一般神奇魔方
		new Array(9803007, 5062002, 35, 1, 1), //高级神奇魔方
		new Array(9803007, 5062009, 20, 1, 1), //超级神奇魔方
		new Array(9803007, 5062010, 14, 1, 1), //终极神奇魔方
		new Array(9803007, 5062001, 14, 1, 1), //混沌神奇魔方
		new Array(9803007, 5062500, 20, 1, 1), //大师附加魔方
		new Array(9803007, 2049137, 22, 1, 1), //惊人正义混沌卷轴 40%
		new Array(9803007, 5150040, 8, 1, 1), //皇家理发卷
		new Array(9803007, 5152053, 8, 1, 1) //皇家整容圈
		//怪物ID，物品ID，爆率，最小值，最大值
	);
function init() {
	em.setProperty("state", "0");
}
function monsterDrop(eim, player, mob) {
	var mobid = mob.getId();
	var toDrop = new Array();
	for (var i = 0; i < dropItems.length; i++) {
		if (mobid != dropItems[i][0])
			continue;
		var chance = Math.floor(Math.random() * 80);
		if (chance < dropItems[i][2]) {
			var minQuantity = dropItems[i][3];
			var maxQuantity = dropItems[i][4];
			var quantity = Math.floor(Math.random() * (maxQuantity - minQuantity + 1) + minQuantity);
			toDrop.push(new Array(dropItems[i][1], quantity)); //载入暴率数组
		}
	}
	for (var i = 0; i < toDrop.length; i++) {
		if (player.getMap() != null)
			player.getMap().spawnMobDrop(em.newItem(toDrop[i][0], 0, toDrop[i][1]), new java.awt.Point(mob.getTruePosition().getX() + 25 * i, mob.getTruePosition().getY()), mob, player, 0, 0);
	}
}
function setup(level, leaderid) {
	var eim = em.newInstance("FLDC");

	var map = eim.setInstanceMap(mapID);
	map.resetPQ(level);
	map.resetFully();
	map.killAllMonsters(true);
	map.respawn(false);

	eim.startEventTimer(1000 * 60 * 40);

	//========================== 最终BOSS 部分结束 ===============================

	mobid = 9803008; //邪恶的蛇兄弟
	mob = em.getMonster(mobid);
	modified = em.newMonsterStats();
	modified.setOHp(15000000000); //20E
	modified.setOMp(mob.getMobMaxMp() * 50);
	modified.setOExp(EXP);
	mob.getStats().setPhysicalAttack(DPS); //物理伤害
	mob.getStats().setMagicAttack(DPS); //魔攻伤害
	mob.getStats().setAcc(500000);
	mob.getStats().setPDRate(60);
	mob.getStats().setMDRate(60);
	mob.getStats().setSpeed(600);
	mob.getStats().setLevel(220);
	mob.getStats().setAcc(500000);
	mob.setOverrideStats(modified);
	mob.getStats().setChange(true); // 让修改生效，否则虽然你那样设置了，召唤出来还是默认属性*/
	eim.registerMonster(mob);
	var mapForMob = eim.getMapInstance(mapID);
	mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(48, 95));

	em.setProperty("state", "1");
	return eim;

}
function playerEntry(eim, player) {
	var map = eim.getMapInstance(0);
	player.dropMessage(6, "[飞龙道场副本] 进入到了挑战地图，请小心行事。");
	player.changeMap(map, map.getPortal(0));
}
function scheduledTimeout(eim) {
	eim.broadcastPlayerMsg(1, "[飞龙道场副本] 本次挑战完毕！期待您下次前来挑战~");
	em.setProperty("state", "0");
	em.setProperty("leader", "true");
}
function cancelSchedule() {}
function playerDead(eim, player) {}
function playerRevive(eim, player) {
	em.setProperty("state", "0");
	em.setProperty("leader", "true");
	return false;
}
function changedMap(eim, player, mapid) { //如果地图状态改变，那么

	switch (mapid) { //实例化地图，不添加也会改变地图，但副本时间会消失。

	case 706041710: //飞龙道场
		var map = eim.getMapInstance(mapID);
		break;
	}

	switch (mapid) { //实例化地图，不添加也会改变地图，但副本时间会消失。
	case 706041710:

		return;
	}

	player.dropMessage(6, "[飞龙道场副本] 已退出挑战。");
	eim.unregisterPlayer(player);
	if (eim.getPlayerCount() <= 0) {
		em.setProperty("state", "0");
		em.setProperty("leader", "true");
	}
}
function playerExit(eim, player) {
	em.setProperty("state", "0");
	em.setProperty("leader", "true");
}

function playerDisconnected(eim, player) {
	eim.unregisterPlayer(player);
	if (eim.getPlayerCount() <= 1) {
		em.setProperty("state", "0");
		em.setProperty("leader", "true");
		if (setupTask != null)
			setupTask.cancel(true);
		eim.dispose();
	}
	return 0;
}
function monsterValue(eim, mobid) { //如果怪物状态改变，那么
	if (mobid == 9803008) { //邪恶的蛇兄弟
		mobid = 9803000; //悟空
		mob = em.getMonster(mobid);
		modified = em.newMonsterStats();
		modified.setOHp(15000000000); //20E
		modified.setOMp(mob.getMobMaxMp() * 50);
		modified.setOExp(EXP);
		mob.getStats().setPhysicalAttack(DPS); //物理伤害
		mob.getStats().setMagicAttack(DPS); //魔攻伤害
		mob.getStats().setAcc(500000);
		mob.getStats().setPDRate(60);
		mob.getStats().setMDRate(60);
		mob.getStats().setSpeed(600);
		mob.getStats().setLevel(220);
		mob.getStats().setAcc(500000);
		mob.setOverrideStats(modified);
		mob.getStats().setChange(true); // 让修改生效，否则虽然你那样设置了，召唤出来还是默认属性*/
		eim.registerMonster(mob);
		var mapForMob = eim.getMapInstance(mapID);
		mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(-718, 95));

		mobid = 9803001; //宋达
		mob = em.getMonster(mobid);
		modified = em.newMonsterStats();
		modified.setOHp(15000000000); //20E
		modified.setOMp(mob.getMobMaxMp() * 50);
		modified.setOExp(EXP);
		mob.getStats().setPhysicalAttack(DPS); //物理伤害
		mob.getStats().setMagicAttack(DPS); //魔攻伤害
		mob.getStats().setAcc(500000);
		mob.getStats().setPDRate(60);
		mob.getStats().setMDRate(60);
		mob.getStats().setSpeed(600);
		mob.getStats().setLevel(220);
		mob.getStats().setAcc(500000);
		mob.setOverrideStats(modified);
		mob.getStats().setChange(true); // 让修改生效，否则虽然你那样设置了，召唤出来还是默认属性*/
		eim.registerMonster(mob);
		var mapForMob = eim.getMapInstance(mapID);
		mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(718, 95));
		//========================================================================================
	} else if (mobid == 9803000) {
		mobid = 9803002; //阿狼
		mob = em.getMonster(mobid);
		modified = em.newMonsterStats();
		modified.setOHp(15000000000); //20E
		modified.setOMp(mob.getMobMaxMp() * 50);
		modified.setOExp(EXP);
		mob.getStats().setPhysicalAttack(DPS); //物理伤害
		mob.getStats().setMagicAttack(DPS); //魔攻伤害
		mob.getStats().setAcc(500000);
		mob.getStats().setPDRate(60);
		mob.getStats().setMDRate(60);
		mob.getStats().setSpeed(600);
		mob.getStats().setLevel(220);
		mob.getStats().setAcc(500000);
		mob.setOverrideStats(modified);
		mob.getStats().setChange(true); // 让修改生效，否则虽然你那样设置了，召唤出来还是默认属性*/
		eim.registerMonster(mob);
		var mapForMob = eim.getMapInstance(mapID);
		mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(-718, 95));

	} else if (mobid == 9803001) {
		mobid = 9803003; //凤仙
		mob = em.getMonster(mobid);
		modified = em.newMonsterStats();
		modified.setOHp(15000000000); //20E
		modified.setOMp(mob.getMobMaxMp() * 50);
		modified.setOExp(EXP);
		mob.getStats().setPhysicalAttack(DPS); //物理伤害
		mob.getStats().setMagicAttack(DPS); //魔攻伤害
		mob.getStats().setAcc(500000);
		mob.getStats().setPDRate(60);
		mob.getStats().setMDRate(60);
		mob.getStats().setSpeed(600);
		mob.getStats().setLevel(220);
		mob.getStats().setAcc(500000);
		mob.setOverrideStats(modified);
		mob.getStats().setChange(true); // 让修改生效，否则虽然你那样设置了，召唤出来还是默认属性*/
		eim.registerMonster(mob);
		var mapForMob = eim.getMapInstance(mapID);
		mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(718, 95));
		//==========================================================================================================
	} else if (mobid == 9803002) {
		mobid = 9803006; //黄龙
		mob = em.getMonster(mobid);
		modified = em.newMonsterStats();
		modified.setOHp(15000000000); //20E
		modified.setOMp(mob.getMobMaxMp() * 50);
		modified.setOExp(EXP);
		mob.getStats().setPhysicalAttack(DPS); //物理伤害
		mob.getStats().setMagicAttack(DPS); //魔攻伤害
		mob.getStats().setAcc(500000);
		mob.getStats().setPDRate(60);
		mob.getStats().setMDRate(60);
		mob.getStats().setSpeed(600);
		mob.getStats().setLevel(220);
		mob.getStats().setAcc(500000);
		mob.setOverrideStats(modified);
		mob.getStats().setChange(true); // 让修改生效，否则虽然你那样设置了，召唤出来还是默认属性*/
		eim.registerMonster(mob);
		var mapForMob = eim.getMapInstance(mapID);
		mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(-718, 95));

	} else if (mobid == 9803003) {
		mobid = 9803007; //赤虎
		mob = em.getMonster(mobid);
		modified = em.newMonsterStats();
		modified.setOHp(15000000000); //20E
		modified.setOMp(mob.getMobMaxMp() * 50);
		modified.setOExp(EXP);
		mob.getStats().setPhysicalAttack(DPS); //物理伤害
		mob.getStats().setMagicAttack(DPS); //魔攻伤害
		mob.getStats().setAcc(500000);
		mob.getStats().setPDRate(60);
		mob.getStats().setMDRate(60);
		mob.getStats().setSpeed(600);
		mob.getStats().setLevel(220);
		mob.getStats().setAcc(500000);
		mob.setOverrideStats(modified);
		mob.getStats().setChange(true); // 让修改生效，否则虽然你那样设置了，召唤出来还是默认属性*/
		eim.registerMonster(mob);
		var mapForMob = eim.getMapInstance(mapID);
		mapForMob.spawnMonsterOnGroundBelow(mob, new java.awt.Point(718, 95));
		//======================================================================================================

	}

	return 1;
}
function monsterKilled(eim, player, cp) {}
function allMonstersDead(eim) {

	eim.setProperty("FBlv", "50"); // - 副本分级
	eim.setProperty("FBnd", "3"); // - 难度等级


	setupTask = em.schedule("Complete", 1000 * 1 * 30, eim); //延迟30秒
	eim.startEventTimer(33000);

	for (var i = 0; i < eim.getPlayerCount(); i++) {
		eim.getPlayers().get(i).dropMessage(6, "[飞龙道场副本] 挑战成功！已召唤击杀奖励！！");
	}
}
function EndThisBattle(eim) {
	/* for (var i = 0; i < eim.getPlayerCount() ; i++) {
	eim.getPlayers().get(i).dropMessage(1, "[飞龙道场副本] 挑战成功！");
	}*/
	//em.broadcastYellowMsg("[飞龙道场副本] 挑战结束");
	eim.disposeIfPlayerBelow(100, 910000000);
	em.setProperty("state", "done");
	em.setProperty("state", "0");
	em.setProperty("leader", "true");
	if (setupTask != null)
		setupTask.cancel(true);
	eim.dispose();
}
function monsterDamaged(eim, player, mobid, damage) {}
function cancelSchedule() {
	if (setupTask != null)
		setupTask.cancel(true);
}
function leftParty(eim, player) {
	em.setProperty("state", "0");
	em.setProperty("leader", "true");
}
function disbandParty(eim) {
	em.setProperty("state", "0");
	em.setProperty("leader", "true");
}

function onMapLoad(eim, player) {}

function openNpc(eim, npcid, mode) {
	for (var i = 0; i < eim.getPlayerCount(); i++) {
		eim.getPlayers().get(i).openNpc(npcid, mode);
	}
}
function pickUpItem(eim, player, itemID) {}
function Complete(eim, player) {
	if (eim.getMapFactory().getMap(mapID).getCharactersSize() != 0) {
		openNpc(eim, 9400496, 2);
	}
}
